package com.mybatis.test.dao;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import lombok.SneakyThrows;
import org.apache.ibatis.datasource.DataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @date 2020-08-12 上午11:34
 */
public class DruidPoolDataSource implements DataSourceFactory {
    private Properties properties;

    @Override
    public void setProperties(Properties props) {
        properties = props;
    }

    @SneakyThrows
    @Override
    public DataSource getDataSource() {
        /*配置初始化大小、最小、最大 */
        properties.put("initialSize", "1");
        properties.put("minIdle", "1");
        properties.put("maxActive", "10");
        /* 配置获取连接等待超时的时间 */
        properties.put("maxWait", "60000");
        return DruidDataSourceFactory.createDataSource(properties);
    }
}
